<?php 
class plus_admin_type
{ 
	function admin_type() 
	{ 
		global $mysql_conn,$v_file;
		$sql = "SELECT * from `plus_type` ";
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$type_id = $row['type_id'];
			$type_name = $row['type_name'];
			$pluslist .= "<tr><td>";
			$pluslist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$pluslist .= "</td>";
			$pluslist .= "<td>".$type_id."</td>";
			$pluslist .= "<td>".$type_name."</td>";
			$pluslist .= "<td>";
			$pluslist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_type_edit(".$type_id.");'><i class='fa fa-edit'></i> 编辑 </a>";
			$pluslist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_type_del(".$type_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$pluslist .= "</td></tr>";
		}
		require($v_file); 
	}
	function admin_type_add_do() 
	{ 
		global $mysql_conn;
		$new_plus_type = $_POST['new_plus_type'];
		$sql = "SELECT * from `plus_type` WHERE `type_name` = '".$new_plus_type."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		if (empty($row)) {
			$sql="INSERT INTO plus_type (type_name) VALUES ('$new_plus_type')";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			echo "2";//应用分类添加成功
		} else {
			echo  "1";//应用分类已存在
		}
	}
	function admin_type_edit() 
	{ 
		global $mysql_conn,$v_file;
		$type_id = $_GET['type_id'];
		$sql = "SELECT * from `plus_type` WHERE `type_id` = '".$type_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$type_name = $row['type_name'];
		require($v_file);
	}
	function admin_type_edit_do() 
	{ 
		global $mysql_conn;
		$type_id = $_POST['type_id'];
		$type_name = $_POST['type_name'];
		$sql = "UPDATE `plus_type` SET `type_name` = '".$type_name."' WHERE `type_id` ='".$type_id."';";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "1";
	}
	function admin_type_del_do() 
	{ 
		global $mysql_conn;
		$type_id = $_POST['type_id'];
		$sql = "DELETE from `plus_type` WHERE `type_id` = '".$type_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "1";
	}
} 
/* End of file democontroller.php */ 